package com.xinqi.common.mybatis.injector.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.xinqi.common.mybatis.injector.enums.ExtSqlMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class SelectByIdWithDeleted extends AbstractMethod {


    public SelectByIdWithDeleted() {
        this(ExtSqlMethod.SELECT_BY_ID_WITH_DELETED.getMethod());
    }

    /**
     * @param name 方法名
     * @since 3.5.0
     */
    public SelectByIdWithDeleted(String name) {
        super(name);
    }


    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        ExtSqlMethod sqlMethod = ExtSqlMethod.SELECT_BY_ID_WITH_DELETED;
        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false), tableInfo.getTableName(),
            tableInfo.getKeyColumn(), tableInfo.getKeyProperty());
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
    }

}
